<template>
  <div style="height: 100%; overflow:hidden" class="main">
    <!-- <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">隐患上报<div id="headeright"  @click="dangereport">上报</div></x-header> -->
    <x-header :left-options="{preventGoBack:true,backText: ''}" @on-click-back="backhome">
      质量检查-离线
      <!-- <x-icon id="headeright" type="ios-plus-empty" size="30" @click="dangereport"></x-icon> -->
      <!-- <img
        slot="right"
        src="@/assets/img/offline_start.png"
        @click="dangereport"
        id="headeright"
        v-if="this.qualityArr.includes('0')"
      />-->
      <img
        slot="right"
        src="@/assets/img/white_change.png"
        class="changeToOnline"
        @click="changeToOnline"
      />
    </x-header>
    <!-- <img
      src="@/assets/img/add_form.png"
      class="add_form"
      @click="dangereport"
      v-if="this.qualityArr.includes('0')"
    />-->
    <div class="add_form_new" @click="dangereport" v-if="this.qualityArr.includes('0')">发起</div>
    <div class="sup"></div>
    <cell is-link link="prjList">
      <span slot="title">{{showPro(pro)}}</span>
    </cell>
    <div class="sup"></div>
    <div class="main-container" style="height:70%;">
      <v-touch v-on:swiperight="onSwipeRight" :swipe-options="{direction: 'horizontal'}">
        <!-- <scroller> -->
        <div style="display: flex;align-items: center;height: 30px;margin-top: 10px;">
          <input
            type="checkbox"
            name="selectAll"
            class="selectHidanger"
            id="selectAll"
            @click="selectAll"
            v-model="checked"
          />
          <label for="selectAll"></label>
          <div>全选</div>
        </div>
        <div>
          <group v-for="(item, i) in list" gutter="-1px" :key="i">
            <div title :border-intent="false" style="display:flex">
              <input
                type="checkbox"
                name="selectHidanger"
                class="selectHidanger"
                :id="item.GUID"
                v-model="checkList"
                :value="item.GUID"
              />
              <label :for="item.GUID" style="width:30px"></label>
              <div class="more-box" style="margin:15px 0;width:100%" @click="openInfo(item)">
                <div class="project_style">
                  <span style="display:inline-block">{{item.PROJECTNAME}}</span>
                </div>
                <div class="state_time_style">
                  <div class="fill_user">
                    <span class="gray-label" style="margin-right: 10px;">填写人</span>
                    {{item.INPUTERFULLNAME}}
                  </div>
                  <div class="fill_time">
                    <span class="gray-label" style="margin-right: 10px;">填写时间</span>
                    {{item.INPUTDATE.substring(0,10)}}
                  </div>
                </div>
              </div>
            </div>
          </group>
        </div>
        <!-- </scroller> -->
      </v-touch>
    </div>
    <!-- <img :src="uploadImgUrl" class="upload" @click="uploadRecodes" v-show="uploadFlag" /> -->
    <div class="upload_div" v-show="uploadFlag">
      <div class="add_form" :disable="isDisable" @click="uploadRecodes">上传</div>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
var $vue = {};
import { Loading } from "vux";
import Vue from "vue";
export default {
  name: "offlinequalitylist",
  components: {
    Loading
  },
  mounted() {
    // this.getData();
    this.getDataOffline();
    this.pageToken = this.guid();
  },
  beforeCreate() {
    $vue = this;
  },
  data() {
    return {
      list: [],
      page: 1,
      keyword: "",
      createPop: false, //弹出层是否创建
      loading: false, //下拉刷新时禁止无限加载
      pro: this.$route.query.pro,
      proId: this.$route.query.proId,
      site: this.$route.query.site,
      pmid: this.$route.query.pmid,
      // guid: "",
      checked: false, //全选框
      checkList: [],
      uploadImgUrl: require("@/assets/img/upload.png"),
      selectedList: [], //已选中的list
      pageToken: "",
      fieldToken: "",
      imgList: this.$store.state.offlineflieurl, //本地图片存储路径
      offlineUrl: [], //要上传至服务器的url
      uploadFlag: false,
      qualityArr: this.$store.state.qualityArr,
      successFlag: 0,
      successFlagUpdate: [],
      isDisable: false
    };
  },
  methods: {
    //上传文件
    upload(fileURL, guid, data, length, index) {
      console.log("upload:" + fileURL, guid);
      var success = r => {
        //上传成功
        console.log("传上成功");
        console.log("rrrrrrr", r);
        this.imgList.map(item => {
          if (true) {
            // if (this.belongSubSys != '') {
            item.fileOldName = JSON.parse(r.response)[0].name;
            item.fileId = JSON.parse(r.response)[0].id;
            item.fieldToken = JSON.parse(r.response)[0].fieldToken;
            item.size = JSON.parse(r.response)[0].size;
            // } else if (this.server != '') {
            // item.fileId = JSON.parse(r.response).fileId // moaapi/feedback 接口
            // }
          }
        });
        if (!this.successFlagUpdate[index]) {
          this.successFlagUpdate[index] = 0;
        }
        this.successFlagUpdate[index]++;
        if (this.successFlagUpdate[index] == length) {
          this.successFlagUpdate[index] = 0;
          delete this.list[index];
          var params = {
            _method: "formService.saveFormData",
            requestEventData: {
              eventType: "formSubmitEvent",
              formType: 1,
              bizObjId: "PMQUALITY_INSPECTION",
              formId: "PMQUALITY_INSPECTION_add",
              buttonId: this.guid()
            },
            _OBJ_NAME_: "PMQUALITY_INSPECTION",
            _FORM_ID_: "PMQUALITY_INSPECTION_add",
            useType: "add",
            pageToken: this.pageToken,
            formData: {
              objName: "PMQUALITY_INSPECTION",
              pks: ["GUID"],
              data: [
                {
                  rowData: [
                    {
                      DataTarget: "GUID",
                      Value: "",
                      OriginalValue: null,
                      PK: true,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FLAG",
                      Value: 0,
                      OriginalValue: null,
                      PK: false,
                      DataType: "int"
                    },
                    {
                      DataTarget: "CENTERPOSITION",
                      Value: data.CENTERPOSITION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FORMNAME",
                      Value: data.FORMNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "FORMNO",
                      Value: data.FORMNO,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PRJNAME",
                      Value: data.PRJNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "SYSPRJID",
                      Value: data.SYSPRJID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "UNITNAME",
                      Value: data.UNITNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "UNITID",
                      Value: data.UNITID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKDATE",
                      Value: data.CHECKDATE + " 00:00:00.000",
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "CHECKYEAR",
                      Value: data.CHECKYEAR,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKMONTH",
                      Value: data.CHECKMONTH,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKYEARANDMONTH",
                      Value: data.CHECKYEARANDMONTH,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKTYPE",
                      Value: data.CHECKTYPE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "DESCRIPTION",
                      Value: data.DESCRIPTION,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "ATTACHMENTS",
                      Value: data.ATTACHMENTS,
                      OriginalValue: null,
                      PK: false,
                      DataType: "Store.ecidiDoc"
                    },
                    {
                      DataTarget: "INPUTERFULLNAME",
                      Value: data.INPUTERFULLNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERNAME",
                      Value: data.INPUTERNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PHONENUM",
                      Value: data.PHONENUM,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERDEPTNAME",
                      Value: data.INPUTERDEPTNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTERDEPTID",
                      Value: data.INPUTERDEPTID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "INPUTDATE",
                      Value: data.INPUTDATE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "TimeStamp"
                    },
                    {
                      DataTarget: "PROJECTNAME",
                      Value: data.PROJECTNAME,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "PROJECTID",
                      Value: data.PROJECTID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKITEM",
                      Value: data.CHECKITEM,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "TYPE",
                      Value: data.TYPE,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "TYPEORDERID",
                      Value: data.TYPEORDERID,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "ISTHIRDPART",
                      Value: '0',
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKQUARTER",
                      Value: data.CHECKQUARTER,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    }
                  ],
                  children: []
                }
              ]
            },
            _ATTACHMENT_DELETE_IDS_: "",
            formInfo: {
              GUID: "",
              FLAG: "0",
              CENTERPOSITION: data.CENTERPOSITION,
              FORMNAME: data.FORMNAME,
              FORMNO: data.FORMNO,
              PRJNAME: data.PRJNAME,
              SYSPRJID: data.SYSPRJID,
              UNITNAME: data.UNITNAME,
              UNITID: data.UNITID,
              CHECKDATE: data.CHECKDATE,
              CHECKYEAR: data.CHECKYEAR,
              CHECKMONTH: data.CHECKMONTH,
              CHECKYEARANDMONTH: data.CHECKYEARANDMONTH,
              CHECKTYPE: data.CHECKTYPE,
              DESCRIPTION: data.DESCRIPTION,
              ATTACHMENTS: data.ATTACHMENTS,
              INPUTERFULLNAME: data.INPUTERFULLNAME,
              INPUTERNAME: data.INPUTERNAME,
              PHONENUM: data.phPHONENUMone,
              INPUTERDEPTNAME: data.INPUTERDEPTNAME,
              INPUTERDEPTID: data.INPUTERDEPTID,
              INPUTDATE: data.INPUTDATE,
              PROJECTID: data.PROJECTID,
              PROJECTNAME: data.PROJECTNAME,
              CHECKITEM: data.CHECKITEM,
              TYPE: data.TYPE,
              TYPEORDERID: data.TYPEORDERID,
              ISTHIRDPART: '0',
              CHECKQUARTER: data.CHECKQUARTER
            }
          };
          let json = {
            FixJSON: JSON.stringify(params)
          };
          console.log("开始保存表单");
          this.$ajax({
            url: this.COMMON_URL + "?_viewId=PMQUALITY_INSPECTION",
            method: "post",
            data: json,
            async: false
          })
            .then(res => {
              console.log("上传成功了吗？", res);
              this.uploadImgUrl = require("@/assets/img/upload.png");

              this.$store.state.SQLiteDB.transaction(
                tx => {
                  tx.executeSql(
                    'DELETE FROM PMQUALITY_INSPECTION WHERE GUID="' +
                      data.GUID +
                      '"'
                  );
                },
                err => {
                  console.log("错误", err);
                }
              );

              this.$store.state.SQLiteDB.transaction(tx => {
                tx.executeSql(
                  "SELECT * FROM PMQUALITY_INSPECTION",
                  [],
                  (tx, result) => {
                    if( result.rows.length == 0 ){
                      this.list = []
                    }
                    for (let i = 0; i < result.rows.length; i++) {
                        this.list[i] = result.rows.item(i);
                    }
                  }
                );
              });
            })
            .catch(err => {
              alert(err);
            });
        }
        // this.showPercent = false
        // this.percent = 0
        //  this.$emit('input', this.list)
        // this.show = false
        // return new Promise((resolve,reject) =>{
        //   resolve(this.successFlag = this.successFlag + 1)
        // })
      };
      var fail = error => {
        // 上传失败
        console.log(JSON.stringify(error));
        // //console.log('photoFailed')
        // this.showPercent = false
        // this.percent = 0
        // console.log("上传失败")
      };
      var options = new FileUploadOptions();
      console.log("fileUpload:" + options);
      options.fileKey = "fileName";
      options.fileName = fileURL.substr(
        fileURL.lastIndexOf("/"),
        fileURL.lastIndexOf("?") - fileURL.lastIndexOf("/")
      );
      if (!options.fileName) {
        options.fileName = fileURL.substr(fileURL.lastIndexOf("/"));
      }
      options.mimeType = "application/octet-stream";
      (options.httpMethod = "POST"),
        (options.headers = {
          Accept: "*/*",
          "Accept-Encoding:": "gzip, deflate",
          "Accept-Language": " zh-CN,zh;q=0.9",
          Connection: "keep-alive"
        });
      (options.chunkedMode = false),
        // 如果要传参数，写这里
        (options.params = {
          Filename: fileURL.substr(fileURL.lastIndexOf("/") + 1),
          Upload: "Submit Query"
          // modularName: 'CNL',
          // allowType: 'jpeg;jpg;png;pdf;doc;xls;xlsx;docx',
        });
      var ft = new FileTransfer();
      //注册监听上传进度
      ft.onprogress = progressEvent => {
        if (progressEvent) {
          this.percent = Math.round(
            (progressEvent.loaded * 100) / progressEvent.total
          );
        }
      };
      let params =
        "type=customerDownloadService&FixJSON={%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:{pageToken:%27" +
        this.pageToken +
        "%27,fieldToken:%27" +
        this.fieldToken +
        "%27,datatype:%27Store.ecidiDoc%27}}";
      if (device.platform == "iOS") {
        // params =
        // "type=customerDownloadService&FixJSON={%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:{pageToken:%27" +
        // this.pageToken + "%27,fieldToken:%27" + this.fieldToken + "%27,datatype:%27Store.ecidiDoc%27}}"
        params =
          "type=customerDownloadService&FixJSON={'_method':'streamSupportService.saveTempAttachment','_param':{'pageToken':'" +
          this.pageToken +
          "','fieldToken':'" +
          this.fieldToken +
          "',datatype:'Store.ecidiDoc'}}";
      }
      //'type=%27customerDownloadService%27&FixJSON=%7B%27_method%27:%27streamSupportService.saveTempAttachment%27,%27_param%27:%7B%27pageToken%27:%27' +
      //  this.pageToken + '%27,%27fieldToken%27:%27' + this.fieldToken + '%27%7D%7D'

      //上传地址
      let SERVER = "";
      // if (this.belongSubSys != '') {
      SERVER =
        this.COMMON_URL.replace("Action.cmd", "StreamSupportAction.cmd") +
        "?" +
        params;
      // }
      // console.log('开始上传'+SERVER)
      // if (this.server != '') {
      //   SERVER = this.server
      //   params = this.params == '' ? '' : this.params
      // }
      console.log("开始上传" + SERVER);
      if (device.platform == "iOS") {
        SERVER = encodeURI(SERVER);
      }
      console.log("optionoffline", options);
      console.log(fileURL);
      ft.upload(fileURL, SERVER, success, fail, options);
    },
    uploadRecodes() {
      this.uploadImgUrl = require("@/assets/img/upload_active.png");
      if (this.checkNetWork()) {
        this.isDisable = true;
        // Vue.$vux.loading.show({
        //       text : "Loading"
        // })
        for (let i = this.selectedList.length - 1; i >= 0; i--) {
          console.log(this.selectedList[i]);
          this.$store.state.SQLiteDB.transaction(tx => {
            tx.executeSql(
              'SELECT * FROM PMQUALITY_INSPECTION WHERE GUID = "' +
                this.selectedList[i] +
                '"',
              [],
              (tx, result) => {
                console.log("上传测试查询结果", result);
                if (result.rows) {
                  (function(i) {
                      $vue.uploadToServer(result.rows.item(0), i);
                    })(i);
                } else {
                  //  alert("请选择需要上传的检查单");
                  this.$vux.alert.show({
                    title:"提示",
                    content:"请选择需要上传的检查单！"
                  })
                }
              }
            );
          });
        }
      } else {
        //执行离线状态时的任务
        console.log("离线工作！");
        // alert("请连接互联网进行上传操作！");
        this.$vux.alert.show({
          title:"提示",
          content:"请连接互联网进行上传操作！"
        })
        
      }
    },
    uploadToServer(data, index) {
      this.fieldToken = data.ATTACHMENTS;
      let res = data.FILEURL;
      res = res.replace(/\|\|/g, ".");
      this.offlineUrl = res.split(",");
      var length = this.offlineUrl.length;
      console.log("图片list", this.imgList);
      if (this.imgList.length == 0) {
        var params = {
          _method: "formService.saveFormData",
          requestEventData: {
            eventType: "formSubmitEvent",
            formType: 1,
            bizObjId: "PMQUALITY_INSPECTION",
            formId: "PMQUALITY_INSPECTION_add",
            buttonId: this.guid()
          },
          _OBJ_NAME_: "PMQUALITY_INSPECTION",
          _FORM_ID_: "PMQUALITY_INSPECTION_add",
          useType: "add",
          pageToken: this.pageToken,
          formData: {
            objName: "PMQUALITY_INSPECTION",
            pks: ["GUID"],
            data: [
              {
                rowData: [
                  {
                    DataTarget: "GUID",
                    Value: "",
                    OriginalValue: null,
                    PK: true,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FLAG",
                    Value: 0,
                    OriginalValue: null,
                    PK: false,
                    DataType: "int"
                  },
                  {
                    DataTarget: "CENTERPOSITION",
                    Value: data.CENTERPOSITION,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FORMNAME",
                    Value: data.FORMNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "FORMNO",
                    Value: data.FORMNO,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PRJNAME",
                    Value: data.PRJNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SYSPRJID",
                    Value: data.SYSPRJID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "UNITNAME",
                    Value: data.UNITNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "UNITID",
                    Value: data.UNITID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKDATE",
                    Value: data.CHECKDATE + " 00:00:00.000",
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "CHECKYEAR",
                    Value: data.CHECKYEAR,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKMONTH",
                    Value: data.CHECKMONTH,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKYEARANDMONTH",
                    Value: data.CHECKYEARANDMONTH,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKTYPE",
                    Value: data.CHECKTYPE,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "DESCRIPTION",
                    Value: data.DESCRIPTION,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "ATTACHMENTS",
                    Value: data.ATTACHMENTS,
                    OriginalValue: null,
                    PK: false,
                    DataType: "Store.ecidiDoc"
                  },
                  {
                    DataTarget: "INPUTERFULLNAME",
                    Value: data.INPUTERFULLNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERNAME",
                    Value: data.INPUTERNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PHONENUM",
                    Value: data.PHONENUM,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERDEPTNAME",
                    Value: data.INPUTERDEPTNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTERDEPTID",
                    Value: data.INPUTERDEPTID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTDATE",
                    Value: data.INPUTDATE,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "PROJECTNAME",
                    Value: data.PROJECTNAME,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTID",
                    Value: data.PROJECTID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "CHECKITEM",
                    Value: data.CHECKITEM,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "TYPE",
                    Value: data.TYPE,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "TYPEORDERID",
                    Value: data.TYPEORDERID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                    {
                      DataTarget: "ISTHIRDPART",
                      Value: '0',
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    },
                    {
                      DataTarget: "CHECKQUARTER",
                      Value: data.CHECKQUARTER,
                      OriginalValue: null,
                      PK: false,
                      DataType: "String"
                    }
                ],
                children: []
              }
            ]
          },
          _ATTACHMENT_DELETE_IDS_: "",
          formInfo: {
            GUID: "",
            FLAG: "0",
            CENTERPOSITION: data.CENTERPOSITION,
            FORMNAME: data.FORMNAME,
            FORMNO: data.FORMNO,
            PRJNAME: data.PRJNAME,
            SYSPRJID: data.SYSPRJID,
            UNITNAME: data.UNITNAME,
            UNITID: data.UNITID,
            CHECKDATE: data.CHECKDATE,
            CHECKYEAR: data.CHECKYEAR,
            CHECKMONTH: data.CHECKMONTH,
            CHECKYEARANDMONTH: data.CHECKYEARANDMONTH,
            CHECKTYPE: data.CHECKTYPE,
            DESCRIPTION: data.DESCRIPTION,
            ATTACHMENTS: data.ATTACHMENTS,
            INPUTERFULLNAME: data.INPUTERFULLNAME,
            INPUTERNAME: data.INPUTERNAME,
            PHONENUM: data.phPHONENUMone,
            INPUTERDEPTNAME: data.INPUTERDEPTNAME,
            INPUTERDEPTID: data.INPUTERDEPTID,
            INPUTDATE: data.INPUTDATE,
            PROJECTID: data.PROJECTID,
            PROJECTNAME: data.PROJECTNAME,
            CHECKITEM: data.CHECKITEM,
            TYPE: data.TYPE,
            TYPEORDERID: data.TYPEORDERID,
            ISTHIRDPART: '0',
            CHECKQUARTER: data.CHECKQUARTER
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        console.log("开始保存表单");
        this.$ajax({
          url: this.COMMON_URL + "?_viewId=PMQUALITY_INSPECTION",
          method: "post",
          data: json,
          async: false
        })
          .then(res => {
            console.log("上传成功了吗？", res);
            this.uploadImgUrl = require("@/assets/img/upload.png");

            this.$store.state.SQLiteDB.transaction(
              tx => {
                tx.executeSql(
                  'DELETE FROM PMQUALITY_INSPECTION WHERE GUID="' +
                    data.GUID +
                    '"'
                );
              },
              err => {
                console.log("错误", err);
              }
            );

            this.$store.state.SQLiteDB.transaction(tx => {
              tx.executeSql(
                "SELECT * FROM PMQUALITY_INSPECTION",
                [],
                (tx, result) => {
                  if( result.rows.length == 0 ){
                    this.list = []
                  }
                  for (let i = 0; i < result.rows.length; i++) {
                      this.list[i] = result.rows.item(i);
                    }
                }
              );
            });
          })
          .catch(err => {
            alert(err);
          });
      } else {
        for (let j = 0; j < this.offlineUrl.length; j++) {
          // this.upload(this.offlineUrl[j], this.imgList[j].guid, data, length);
          (function(j) {
            $vue.upload($vue.offlineUrl[j], $vue.guid(), data, length, index);
          })(j);
        }
      }
      if (index == 0) {
        setTimeout(() => {
          this.isDisable = false;
        }, 3000);
      }
    },
    selectAll() {
      if (this.checked) {
        //实现反选
        this.checkList = [];
      } else {
        //实现全选
        this.checkList = [];
        for (var i = 0; i < this.list.length; i++) {
          this.checkList.push(this.list[i].GUID);
        }
      }
    },
    //切换至在线模式
    changeToOnline() {
      this.$router.push({
        name: "qualityReport",
        path: "/qualityReport"
      });
    },
    onSwipeRight() {
      this.$router.push("/index/home");
    },
    backhome() {
      this.$router.push("/index/home");
    },
    getDataOffline() {
      if (this.proId != undefined) {
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            "SELECT * FROM PMQUALITY_INSPECTION where PROJECTID = '" +
              this.proId +
              "'",
            [],
            (tx, result) => {
              console.log(result);
              for (let i = 0; i < result.rows.length; i++) {
                  this.list[i] = result.rows.item(i);
                }
              if (this.list.length > 0) {
                this.uploadFlag = true;
              }
            }
          );
        });
      } else {
        this.$store.state.SQLiteDB.transaction(tx => {
          tx.executeSql(
            "SELECT * FROM PMQUALITY_INSPECTION",
            [],
            (tx, result) => {
              console.log(result);
              for (let i = 0; i < result.rows.length; i++) {
                  this.list[i] = result.rows.item(i);
                }
              if (this.list.length > 0) {
                this.uploadFlag = true;
              }
            }
          );
        });
      }
    },
    getData(callback, failed) {
      var filter = "1=1";
      if (!this.proId) {
        filter = "1=1";
      } else {
        filter = "PROJECTID='" + this.proId + "'";
      }
      var params =
        '{"_method":"component.getListData","_param":{"bizObj":"PMQUALITY_INSPECTION","service":"selectMore","fields":"*","filter":' +
        '"' +
        filter +
        '"' +
        ',"currentPageIndex":1,"pageSize":50,"orderList":[{"field":"INPUTDATE","order":"desc"}],"QueryFormData":""}}';
      this.$ajax({
        method: "post",
        url:
          this.COMMON_URL +
          "?_objName=PMQUALITY_INSPECTION&_viewId=PMQUALITY_INSPECTION",
        data: {
          FixJSON: params
        }
      })
        .then(res => {
          this.list = [...res.data.datas];
          //console.log(this.list)
          this.page++;
        })
        .catch(err => {
          failed();
        });
    },
    openInfo(item) {
      this.$router.push({
        path: "/qualityReport/offlineQualityDetail",
        query: {
          GUID: item.GUID,
          pro: item.PROJECTNAME,
          site: item.CENTERPOSITION,
          pmname: item.PRJNAME
        }
      });
    },
    infinite(done) {
      //上划加载方法
      this.getData(res => {
        this.list = [...this.list, ...res.data.datas]; //TODO 啥意思
        this.page++;
        done();
      });
    },
    refresh(done) {
      this.page = 1;
      this.getData(res => {
        this.list = [...res.data.datas];
        this.page++;
      });
    },
    search(val) {
      this.page = 1;
      this.keyword = val;
      this.getData(
        res => {
          if (res.status == "200" && res.data.datas.length > 0) {
            this.list = [...res.data.datas];
            this.page++;
          } else {
            this.list = [];
          }
        },
        () => {
          this.list = [];
        }
      );
    },
    dangereport() {
      console.log(this.$route.query);
      this.$router.push({
        path: "/qualityReport/InspectionInfo",
        query: this.$route.query
      });
    },
    changeType(val) {
      this.page = 1;
      this.currentTab = val;
      this.list = [];
      this.$refs.taskScroller.finishInfinite(false);
    },
    showPro(pro) {
      return !!pro ? pro : "全部项目";
    }
  },

  computed: {
    row() {
      //页面中使用row来指代当前记录
      return this.$store.state.currentRow;
    }
  },
  watch: {
    proId: function(newId, old, Id) {},
    checkList: {
      handler: function(val, oldVal) {
        this.selectedList = this.checkList;
        if (val.length === this.list.length) {
          this.checked = true;
        } else {
          this.checked = false;
        }
      },
      deep: true
    }
    // successFlag:function(newId, old, Id) {
    //   this.successFlagUpdate = newId
    //   console.log("successFlagUpdate",this.successFlagUpdate)
    // }
  }
};
</script>

<style scoped>
.transition-view /deep/ .vux-header .vux-header-left .left-arrow:before {
  border-color: #cccccc;
}
.transition-view /deep/ .vux-header {
  background-color: #262a34 !important;
}
.transition-view .vux-header /deep/ .vux-header-title {
  color: #ffffff;
}
.card {
  background: #fff;
  margin: 10px 16px;
  padding: 20px;
  border-radius: 4px;
  overflow: hidden;
}

.card-title {
  font-size: 18px;
}
.warning {
  color: red;
  padding: 0 5px;
  background-color: pink;
  text-align: center;
  width: 140px;
  line-height: 30px;
  font-size: 14px;
}

.gray-label {
  color: gray;
}

#headeright {
  position: absolute;
  right: 0px;
  top: 5px;
  display: block;
  font-size: 14px;
  line-height: 21px;
  width: 20px;
  height: 20px;
}
.box-bar:before {
  content: "";
  display: block;
  height: 17px;
  position: absolute;
  border-left: 4px solid #a7aeff;
  left: 14px;
  top: 18px;
}
.hidanger-chosetaskfontshow {
  max-width: 70px;
  overflow-x: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
  /*设置overflow后基线位置改变，因此需要调整*/
  vertical-align: bottom;
}
.changeToOnline {
  margin-right: auto;
  width: 25px;
  height: 25px;
  /* margin-top: 10px; */
}
.selectHidanger {
  display: none;
}
.selectHidanger + label {
  background-color: #eeeeee;
  border-radius: 4px;
  border: 1px solid #d3d3d3;
  width: 20px;
  height: 20px;
  display: inline-block;
  text-align: center;
  vertical-align: bottom;
  line-height: 20px;
  margin: 25px;
}
.selectHidanger + label:hover {
  cursor: pointer;
  border: 1px solid #262a34;
}
.selectHidanger:checked + label {
  background-color: #eeeeee;
  background: #262a34;
}
.selectHidanger:checked + label:after {
  content: "\2714";
  color: white;
}
.upload {
  z-index: 999;
  position: absolute;
  top: 75%;
  left: 80%;
  width: 50px;
  height: 50px;
}
.add_form {
  position: relative;
  height: 50px;
  width: 90%;
  top: 8px;
  z-index: 999;
  left: 5%;
  background: #262a34;
  color: #ffffff;
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add_form_new {
  position: absolute;
  width: 50px;
  height: 50px;
  top: 80%;
  z-index: 999;
  left: 80%;
  background: #262a34;
  box-shadow: 0px 1px 13px 0px #262a34;
  border-radius: 50%;
  color: #ffffff;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sup {
  width: 100%;
  height: 10px;
  border-radius: 0;
  background-color: #f5f5f5;
}
.project_style {
  font-size: 15px;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(25, 25, 25, 1);
  line-height: 20px;
  margin-top: 8px;
}
.state_time_style {
  display: flex;
  margin-top: 8px;
}
.fill_user {
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(175, 175, 175, 1);
  line-height: 20px;
}
.fill_time {
  margin-left: auto;
  font-size: 12px;
  font-family: PingFang SC;
  font-weight: 400;
  color: rgba(175, 175, 175, 1);
  line-height: 20px;
  margin-right: auto;
}
/* .transition-view .vux-header .vux-header-left /deep/.left-arrow:before{
   border: 1px solid rgb(228, 15, 15);
 } */
.upload_div {
  border-top: 1px solid rgb(238, 238, 238);
  /* position: relative;
    bottom: 60px; */
}
</style>
